package org.kabeja.dxf.entity;

import org.kabeja.dxf.DXFConstants;
import org.kabeja.dxf.helpers.DXFMLineSegment;
import org.kabeja.dxf.helpers.MLineConverter;
import org.kabeja.dxf.helpers.Point;

import java.util.ArrayList;
import java.util.List;

/**
 * @author shutao
 * @since 2022/4/25 9:15
 */
public class DXFMLine extends DXFEntity {
    public static final int JUSTIFICATION_TOP = 0;
    public static final int JUSTIFICATION_ZERO = 1;
    public static final int JUSTIFICATION_BOTTOM = 2;
    protected double scale = 1.0D;
    protected Point startPoint = new Point();
    protected List<DXFMLineSegment> mlineSegments = new ArrayList<>();
    protected int lineCount = 0;
    protected int justification = 0;
    protected String mLineStyleID = "";
    protected String mLineStyleName = "";

    public DXFMLine() {
        this.setLineType(this.getType());
    }

    @Override
    public Bounds getBounds() {
        Bounds var1 = new Bounds();
        DXFPolyline[] var2 = this.toDXFPolylines();

        for(int var3 = 0; var3 < var2.length; ++var3) {
            var1.addToBounds(var2[var3].getBounds());
        }

        return var1;
    }

    @Override
    public String getType() {
        return DXFConstants.ENTITY_TYPE_MLINE;
    }

    @Override
    public double getLength() {
        DXFPolyline[] var1 = this.toDXFPolylines();
        double var2 = 0.0D;

        for(int var4 = 0; var4 < var1.length; ++var4) {
            var2 += var1[var4].getLength();
        }

        return var2;
    }

    public void addDXFMLineSegement(DXFMLineSegment var1) {
        this.mlineSegments.add(var1);
    }

    public int getDXFMLineSegmentCount() {
        return this.mlineSegments.size();
    }

    public DXFMLineSegment getDXFMLineSegment(int var1) {
        return this.mlineSegments.get(var1);
    }

    public double getScale() {
        return this.scale;
    }

    public void setScale(double var1) {
        this.scale = var1;
    }

    public Point getStartPoint() {
        return this.startPoint;
    }

    public void setStartPoint(Point var1) {
        this.startPoint = var1;
    }

    public int getLineCount() {
        return this.lineCount;
    }

    public void setLineCount(int var1) {
        this.lineCount = var1;
    }

    public String getMLineStyleID() {
        return this.mLineStyleID;
    }

    public void setMLineStyleID(String var1) {
        this.mLineStyleID = var1;
    }

    public int getJustification() {
        return this.justification;
    }

    public void setJustification(int var1) {
        this.justification = var1;
    }

    public String getMLineStyleName() {
        return this.mLineStyleName;
    }

    public void setMLineStyleName(String var1) {
        this.mLineStyleName = var1;
    }

    protected DXFPolyline[] toDXFPolylines() {
        return MLineConverter.toDXFPolyline(this);
    }

    public boolean isClosed() {
        return (this.flags & 2) == 2;
    }
}
